package com.egao.common.module.workLog.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.workLog.entity.WorkLog;
import com.egao.common.module.workLog.entity.vo.WorkLogVO;
import com.egao.common.module.workLog.service.WorkLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 控制器
 *
 * @author shu
 */
@Api(tags = "工作日志管理")
@RestController
@RequestMapping("${api}")
public class WorkLogController extends BaseController {

    private WorkLogService workLogService;

    @Autowired
    public WorkLogController(WorkLogService workLogService) {
        this.workLogService = workLogService;
    }

    @PreAuthorize("hasAuthority('work:log:list')")
    @ApiOperation(value = "查询工作日志列表")
    @ApiPageParam
    @GetMapping("/work/log/list")
    public PageResult<WorkLogVO> listPage(HttpServletRequest request) {
        PageParam<WorkLog> pageParam = new PageParam<>(request);
        return workLogService.listPage(pageParam);
    }

    @PreAuthorize("hasAuthority('work:log:add')")
    @ApiOperation("添加工作日志")
    @PostMapping("/work/log/add")
    public JsonResult insert(@RequestBody WorkLogVO model) {
        return workLogService.insertWorkLog(model);
    }

    @PreAuthorize("hasAuthority('work:log:update')")
    @ApiOperation("修改工作日志")
    @PostMapping("/work/log/update")
    public JsonResult update(@RequestBody WorkLogVO model) {
        return workLogService.updateWorkLog(model);
    }

    @PreAuthorize("hasAuthority('work:log:delete')")
    @ApiOperation("删除工作日志")
    @GetMapping("/work/log/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return workLogService.deleteWorkLog(ids);
    }

    @PreAuthorize("hasAuthority('work:log:read')")
    @ApiOperation("查询单个工作日志")
    @GetMapping("/work/log/read/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return workLogService.read(id);
    }

    @PreAuthorize("hasAuthority('work:log:summary')")
    @ApiOperation("周汇总")
    @GetMapping("/work/log/summary")
    public JsonResult summary(String date, Integer userId) {
        return workLogService.summary(date, userId);
    }

    @PreAuthorize("hasAuthority('work:log:summary')")
    @ApiOperation("范围汇总")
    @GetMapping("/work/log/summaryAll")
    public JsonResult summaryAll(String beginDate, String endDate, Integer userId) {
        return workLogService.summaryAll(beginDate, endDate, userId);
    }

    @PreAuthorize("hasAuthority('work:log:list')")
    @ApiOperation(value = "查询就业中心人员")
    @ApiPageParam
    @GetMapping("/work/log/worker/list")
    public JsonResult list(String con) {
        return workLogService.selectWorker(con);
    }

}